package com.my.controller;


import com.alibaba.fastjson.JSONObject;
import com.my.bean.*;
import com.my.service.PickingService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import javax.xml.ws.Action;

import javax.xml.ws.Response;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
/**
 * <p>
 * 入库 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2018-08-24
 */
@Controller
@RequestMapping("/picking")
public class PickingController {
    @Autowired
    PickingService pickingService;

    //添加
    @RequestMapping( "/insertPicking")
    @ResponseBody
    public String insertPicking(String param,HttpSession session){
        System.out.println(param);

        try {
            boolean admin=false;
            //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
            if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
                admin=true;
            }

            Long areaid = ((User)session.getAttribute("user")).getAreaId();
            return   pickingService.insertMa(param,areaid,admin);
        } catch (SQLException e) {
            return "添加失败，服务器错误";
        }

    }

    /**
     * 查询并分页
     * @param voPage
     * @return
     */
    @RequestMapping("/selectPicking")
    @ResponseBody
    public ResultPage <Picking> selectPicking(Picking picking, VoPage voPage,HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Long areaid = ((User)session.getAttribute("user")).getAreaId();
        ResultPage<Picking> resultPage = pickingService.selectMyPage(picking,voPage, areaid,admin);
        return resultPage;
    }


    @RequestMapping("/pick")
    public String pick() {
        return "picking";
    }


    @RequestMapping("/picking_add.html")
    public String Pick(){
        return  "/Alert/picking_add";
    }
}

